﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Class1
    {
        public static void UserInfo()
        {
            string connStr = "server=.;database=test;uid=sa;Pwd=123456";
            SqlConnection conn = new SqlConnection(connStr);
            conn.Open();
            var sql = "select * from userInfo";
            SqlCommand sqlcmd = new SqlCommand(sql, conn);
            var sqldr = sqlcmd.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}", "Id", "用户名", "年龄");
            while (sqldr.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", sqldr["userId"], sqldr["userName"], sqldr["userAge"]);

            }
            conn.Close();
        }

        private readonly string conn = "server=.;database=test;uid=sa;Pwd=123456";
        private readonly string sqlconn = "select * from userInfo";
        public void Seachuse()
        {
            SqlDataAdapter sqlsad = new SqlDataAdapter(sqlconn, conn);
            DataTable dt = new DataTable();
            sqlsad.Fill(dt);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("{0}\t{1}\t{2}", "Id", "用户名", "年龄");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", dt.Rows[i]["Id"], dt.Rows[i]["userName"], dt.Rows[i]["userAge"], dt.Rows[i]["StudentAge"], dt.Rows[i]["StudentScore"]);
            }
        }
    }
}
